package com.smartthinking.CICPNL.home.activity;

import java.util.ArrayList;
import java.util.Dictionary;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.smartthinking.CICPNL.R;
import com.smartthinking.CICPNL.R.id;
import com.smartthinking.CICPNL.home.objects.App_ImageLoader;
import com.smartthinking.CICPNL.home.xml.saxXML;

public class Panoramas extends Activity {

	private ImageView imagen;
	private TextView titulo;
	private Dictionary dic;
	public ArrayList<Dictionary> Actividades;
	public static ArrayList<Dictionary> TraeDatos = null;
	public ListView list;
	public ListAdapter adapter;
	public Dialog progressDialog;
	public App_ImageLoader imageLoader;
	private Intent intent;
	public Integer EVEIDR;

	
	public void voidFinish(View V) {
		finish();

	}
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);

		// Checks the orientation of the screen
		 
	}
	public void abrirMenuLateral(View V) {
		intent = new Intent(Panoramas.this, MenuLateral.class);

		startActivity(intent);
	}
	
	@Override
	public void onBackPressed() {
	}	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.ui_panoramas);

	/********************************************************************************
     	Obtiene Id del evento
    */
    
    String strEve = "select eve_idr from eventos where eve_idr=1";
	 
	 Utilities findEve = new Utilities();
	 findEve.qry(this,findEve.escape(strEve));
	 TraeDatos = findEve.Actividades;
	 EVEIDR = Integer.parseInt(TraeDatos.get(0).get("eve_idr").toString());
	 /********************************************************************************/

	}
	

	private class AsyncActividades extends AsyncTask<String, Void, Integer> {

		protected void onPostExecute(Integer in) {

			list = (ListView) findViewById(R.id.list);
			adapter = new Hoteles_Adapter(Actividades);
			list.setAdapter(adapter);

			list.setTextFilterEnabled(true);

			list.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {

					Intent intent = new Intent(Panoramas.this, Web.class);
					//

					Display display = getWindowManager().getDefaultDisplay();
					int width = display.getWidth();
					int height = display.getHeight();

					intent.putExtra("PUTWEB",
							Actividades.get(position).get("c360_url")
									.toString()
									+ "?w=" + width + "&h=" + height);

					//
					startActivity(intent);

					// finish();

				}
			});
			progressDialog.dismiss();

			// abrirSplashBanner();
		}

		protected void onPreExecute() {

			progressDialog = ProgressDialog.show(Panoramas.this, "",
					"Cargando...");
		}

		@SuppressWarnings("rawtypes")
		protected Integer doInBackground(String... urls) {

			// "select * from ponentes where eve_idr = %@ order by pon_nombre"
			String qry_url = getString(R.string.QRY_URL)
					+ Uri.encode("select * from cintermex_360");

			saxXML saxparser = new saxXML(qry_url);

			Actividades = saxparser.parse();

			return null;

		}

	}

	public class Hoteles_Adapter extends BaseAdapter {

		private LayoutInflater inflater = null;
		private ArrayList<Dictionary> data;

		public Hoteles_Adapter(ArrayList<Dictionary> d) {

			data = d;
			inflater = (LayoutInflater) Panoramas.this
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			imageLoader = new App_ImageLoader(
					Panoramas.this.getApplicationContext());

		}

		public int getCount() {
			return data.size();
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public class ViewHolder {

			public TextView tvTitulo;
			// public ImageView images;

		}

		public View getView(int position, View convertView, ViewGroup parent) {

			View vi = convertView;
			ViewHolder holder;

			if (convertView == null) {

				vi = inflater.inflate(R.layout.ui_panoramas_items, null);

				holder = new ViewHolder();

				holder.tvTitulo = (TextView) vi
						.findViewById(R.id.tv_panoramasitems_ponente);

				// holder.images = (ImageView) vi
				// .findViewById(R.id.iv_panoramasitems_imagen);

				vi.setTag(holder);

			} else

				holder = (ViewHolder) vi.getTag();

			String Titulo = data.get(position).get("c360_desc").toString();

			holder.tvTitulo.setText(Titulo);

			// String url_img = getString(R.string.QRY_URL_IMG)
			// + data.get(position).get("c360_url").toString()
			// .replace(" ", "%20");
			//
			//
			// holder.images.setTag(url_img);
			//
			// try {
			//
			// imageLoader
			// .DisplayImage(url_img, Panoramas.this, holder.images);
			//
			// } catch (Exception ex) {
			//
			// String s = ex.getMessage().toString();
			//
			// }

			return vi;

		}
	}

}